package com.day240701.dao;

import com.day240701.util.JDBCUtils;

import java.sql.ResultSet;

public class AdminDao {
    public int getVisitCount() {
        // 从数据库取出 visit_count
        int visitCount = 0;
        ResultSet rs = JDBCUtils.doQuery("select visit_count from t_visit_record order by update_date desc limit 1;");
        try {
            while (rs.next()) {
                visitCount = rs.getInt("visit_count");
            }
        } catch(Exception e) {
            e.printStackTrace();
        } finally {
            JDBCUtils.doClose(rs);
        }

        return visitCount;
    }

    // 将数据 访问次数 保存到 t_visit_record 表中
    public boolean saveVisitCount(int visitCount) {
        int count = JDBCUtils.doUpdate("insert into t_visit_record(visit_count, update_date)values(?, SYSDATE())", visitCount);
        return count > 0;
    }
}
